﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using Adrr.Model;
namespace Adrr.BLL
{
    /// <summary>
    /// Base_Dept
    /// </summary>
    public partial class Base_Dept
    {
        private readonly Adrr.DAL.Base_Dept dal = new Adrr.DAL.Base_Dept();
        public Base_Dept()
        { }
        #region  Method
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string DeptID)
        {
            return dal.Exists(DeptID);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Adrr.Model.Base_Dept model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Adrr.Model.Base_Dept model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string DeptID)
        {

            return dal.Delete(DeptID);
        }
        /// <summary>
        /// 把该部门标记为已经删除(包括它的子部门)
        /// </summary>
        public bool SetThisDeptIsDeleted(string DeptID)
        {
            return dal.SetThisDeptIsDeleted(DeptID);
        }
        /// <summary>
        /// 把该企业标记为已经删除(包括它下面的部门也标记为已删除)
        /// </summary>
        /// <param name="CompanyId"></param>
        /// <returns></returns>
        public bool SetThisCompanyIsDepted(string CompanyId)
        {
            return dal.SetThisCompanyIsDepted(CompanyId);
        }
        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool DeleteList(string DeptIDlist)
        {
            return dal.DeleteList(DeptIDlist);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Adrr.Model.Base_Dept GetModel(string DeptID)
        {

            return dal.GetModel(DeptID);
        }

        /// <summary>
        /// 得到一个对象实体，从缓存中
        /// </summary>
        public Adrr.Model.Base_Dept GetModelByCache(string DeptID)
        {

            string CacheKey = "Base_DeptModel-" + DeptID;
            object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
            if (objModel == null)
            {
                try
                {
                    objModel = dal.GetModel(DeptID);
                    if (objModel != null)
                    {
                        int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
                        Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
                    }
                }
                catch { }
            }
            return (Adrr.Model.Base_Dept)objModel;
        }

        /// <summary>
        /// 只获取DeptID和DeptName
        /// </summary>
        public DataSet GetDeptIdAndDeptName()
        {
            return dal.GetDeptIdAndDeptName();
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }
        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Adrr.Model.Base_Dept> GetModelList(string strWhere)
        {
            DataSet ds = dal.GetList(strWhere);
            return DataTableToList(ds.Tables[0]);
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List<Adrr.Model.Base_Dept> DataTableToList(DataTable dt)
        {
            List<Adrr.Model.Base_Dept> modelList = new List<Adrr.Model.Base_Dept>();
            int rowsCount = dt.Rows.Count;
            if (rowsCount > 0)
            {
                Adrr.Model.Base_Dept model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new Adrr.Model.Base_Dept();
                    if (dt.Rows[n]["DeptID"] != null && dt.Rows[n]["DeptID"].ToString() != "")
                    {
                        model.DeptID = dt.Rows[n]["DeptID"].ToString();
                    }
                    if (dt.Rows[n]["DeptName"] != null && dt.Rows[n]["DeptName"].ToString() != "")
                    {
                        model.DeptName = dt.Rows[n]["DeptName"].ToString();
                    }
                    if (dt.Rows[n]["DeptBriefName"] != null && dt.Rows[n]["DeptBriefName"].ToString() != "")
                    {
                        model.DeptBriefName = dt.Rows[n]["DeptBriefName"].ToString();
                    }
                    if (dt.Rows[n]["IsWorkDress"] != null && dt.Rows[n]["IsWorkDress"].ToString() != "")
                    {
                        if ((dt.Rows[n]["IsWorkDress"].ToString() == "1") || (dt.Rows[n]["IsWorkDress"].ToString().ToLower() == "true"))
                        {
                            model.IsWorkDress = true;
                        }
                        else
                        {
                            model.IsWorkDress = false;
                        }
                    }
                    if (dt.Rows[n]["PhoneNum"] != null && dt.Rows[n]["PhoneNum"].ToString() != "")
                    {
                        model.PhoneNum = dt.Rows[n]["PhoneNum"].ToString();
                    }
                    if (dt.Rows[n]["CreateTime"] != null && dt.Rows[n]["CreateTime"].ToString() != "")
                    {
                        model.CreateTime = DateTime.Parse(dt.Rows[n]["CreateTime"].ToString());
                    }
                    if (dt.Rows[n]["UpdateTime"] != null && dt.Rows[n]["UpdateTime"].ToString() != "")
                    {
                        model.UpdateTime = DateTime.Parse(dt.Rows[n]["UpdateTime"].ToString());
                    }
                    if (dt.Rows[n]["isDelete"] != null && dt.Rows[n]["isDelete"].ToString() != "")
                    {
                        if ((dt.Rows[n]["isDelete"].ToString() == "1") || (dt.Rows[n]["isDelete"].ToString().ToLower() == "true"))
                        {
                            model.isDelete = true;
                        }
                        else
                        {
                            model.isDelete = false;
                        }
                    }
                    if (dt.Rows[n]["PinYin"] != null && dt.Rows[n]["PinYin"].ToString() != "")
                    {
                        model.PinYin = dt.Rows[n]["PinYin"].ToString();
                    }
                    modelList.Add(model);
                }
            }
            return modelList;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            return dal.GetRecordCount(strWhere);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            return dal.GetListByPage(strWhere, orderby, startIndex, endIndex);
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        #endregion  Method
    }
}

